
import java.awt.*;
import javax.swing.*;

public class SystemTrayProgGUI extends ProgressGUI {

   private SystemTray tray = SystemTray.getSystemTray();
   private TrayIcon trayIcon = null;
   private PopupMenu popupMenu = null;
   private MenuItem stageItem = null;
   private MenuItem progressItem = null;

   public SystemTrayProgGUI( int workTimeMin, int breakTimeMin, int voteTimeMin ) {
      super( workTimeMin, breakTimeMin, voteTimeMin );
      System.out.println( "SystemTrayProgGUI" );

      // Make a Popup Menu for the tray icon
      popupMenu = new PopupMenu( "DARSI" );
      stageItem = new MenuItem( "Initializing" );
      progressItem = new MenuItem( "0 mins" );

      popupMenu.add( stageItem );
      popupMenu.addSeparator();
      popupMenu.add( progressItem );

      // Make a Tray Icon
      trayIcon = new TrayIcon( Darsi.image, "DARSI", popupMenu );
      try{
         tray.add( trayIcon );
      } catch( AWTException e ) {
         e.printStackTrace();
      }
   }

   private void setStageTitle( int stage ) {
      stageItem.setLabel( ProgressGUI.stages[ stage-1 ] );
      System.out.println( "Stage: " + ProgressGUI.stages[ stage-1 ] );
   }
   
   public void setProgress( int stage, int progress ) {
      super.setProgress( stage, progress );
      String progressStr = "" + progress + " / ";
      if( stage == ProgressGUI.WORK_STAGE ) {
         progressStr += Darsi.DARSI_DEFAULT_WAIT_MINS;
      } else if ( stage == ProgressGUI.BREAK_STAGE ) {
         progressStr += Darsi.DARSI_DEFAULT_BREAK_MINS;
      } else {
         progressStr += Darsi.DARSI_DEFAULT_VOTE_MINS;
      }
      progressStr += " mins";
      progressItem.setLabel( progressStr );
      setStageTitle( stage );
      System.out.println( "Progress: " + progress );
   }

}
